package com.erlang.spring.controller;

import com.erlang.spring.pojo.Account;
import com.erlang.spring.service.AccountService;
import com.erlang.spring.service.DealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * @Description：账户服务,controller层
 */
@Controller("accountController")
public class AccountController {

  @Autowired
  private AccountService accountService;

  @Autowired
  private DealService dealService;

  /**
   * 创建用户
   */
  public int saveAccount(Account account) {
    return accountService.saveAccount(account);
  }

  /**
   * 删除用户
   */
  public int deleteAccountById(int id) {
    return accountService.deleteAccountById(id);
  }

  /**
   * 修改用户
   */
  public int updateAccountById(Account account) {
    return accountService.updateAccountById(account);
  }


  /**
   * 按ID查询用户
   */
  public Account findAccountById(int id) {
    return accountService.findAccountById(id);
  }

  /**
   * 查询所有用户
   */
  public List<Account> findAll() {
    return accountService.findAll();
  }

  /**
   * 统计用户个数
   */
  public Integer countAccount() {
    return accountService.countAccount();
  }


  /**
   * 交易
   */
  public void doDeal(){
    System.out.println("交易之前：");
    dealService.printAccountInfo(1, 2);
    dealService.doDeal(100F, 1, 2);
    System.out.println("交易之后：");
    dealService.printAccountInfo(1, 2);
  }

  public void setAccountService(AccountService accountService) {
    this.accountService = accountService;
  }
}
